/**
 * Created by Forcs on 16/4/15.
 */

var model = require('../db/Model');
var co = require('co');
var ModelManager = require('../db/ModelManager');

var FlavorsManager = function () {
  this._cached = {};
};

FlavorsManager.prototype.allWithBiz = function (biz, projection, options, func) {
  var self = this;
  return new Promise(function (resolve, reject) {
    co(function * () {
      var querySet = undefined;
      if (self._cached[biz]) {
        querySet = self._cached[biz];
      }
      if (!querySet) {
        querySet = self.find({ biz: biz }, projection, options, func);
        self._cached[biz] = querySet;
      }
      resolve(self._cached[biz]);
    }).catch(function (err) {
      reject(err);
    })
  });
};

module.exports = model.create('Flavors', {
  id: String,
  name: String,
  biz: String
}, { biz: 1, id: 1 }, FlavorsManager);